<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>基金买卖计算器</title>
<link href="css/common.css" type="text/css" rel="stylesheet" />
<script languge=javascript src="js/time.js"></script>
<script languge=javascript src="js/calculator.js"></script>
<script languge=javascript src="js/dealdata.js"></script>
<script language="javascript"> 
var win=null;
function popwin(fileurl){
  win=window.open(fileurl,"popwin",
"toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=0,width=600,height=500");
 win.focus();
}
function fundgetrate(){
 var code1=document.fundsb.code.value;
        var buyrate1;
        var redeemrate1;
        var buyrate2;
        var true1=0;
        var n=document.fundsb.sellbuy.selectedIndex;
        for(i=0;i<=codeArray.length;i++)
          {
          if (codeArray[i]==code1)
            {
            buyrate1=buyrateArray[i];
            redeemrate1=redeemArray[i];
            buyrate2=buyrate2Array[i];
            true1=1;
            }
          }
        if(true1==0){
        alert("请输入正确的基金代码!");
        document.fundsb.code.focus();
        return;
        }
   if(n==1)   document.fundsb.rate.value=buyrate1;
   else if(n==2)   document.fundsb.rate.value=buyrate2;
   else if(n==3)   document.fundsb.rate.value=redeemrate1;
}
 
function getprice(){
        if(document.fundsb.inputSelect.value="自动")
        {
        var m=document.fundsb.debtkindFrom.selectedIndex;
        var n=document.fundsb.sellbuy.selectedIndex;
 
        if(m==0){
                alert("选择股票代码！");
                document.fundsb.debtkindFrom.focus();
                return;
               }
        if(n==0){
                alert("选择操作类型！");
                document.fundsb.sellbuy.focus();
                return;
               }
 
        if(n==1)  {document.fundsb.price.value=buyArray[m];}
        else    {document.fundsb.price.value=sellArray[m];}
     }
}
//计算函数，返回计算结果并显示在相应的结果项上。
function fundsendprice(){
        //设定一个数组，把要检验的字段对应的输入框的字符串表示赋给数组
        var objArray=new Array;
        var objArray1=new Array;
        var i;
        objArray[0]=document.fundsb.buyMoneyNum;//用户交纳金额或者已经购买的份额
        objArray[1]=document.fundsb.price; //基金价格
		    objArray[2]=document.fundsb.rate; //费率
      //  objArray1[0]=document.fundsb.price; //基金价格
      //  objArray1[1]=document.fundsb.rewardMoneyNum; //用户得到的金额或者份额
        
 
        var rst=checkData(objArray);//调用函数检验是否有空字符
 
       // var code1=document.fundsb.code.value;
        var n=document.fundsb.sellbuy.selectedIndex;
        var rate=document.fundsb.rate.value;
        if(n==0){
                alert("选择操作类型！");
                document.fundsb.sellbuy.focus();
                return;
               }
         else{
		    if(rst=="false")return;//输入项不完整
			else{//开始计算 
			 switch(n){
			 //申购
			 case 1: var buymoney =document.fundsb.buyMoneyNum.value;
			         var price=document.fundsb.price.value;
					 var r1=parseFloat(buymoney)/(1+parseFloat(rate)/100);//净申购金额 
					 var resultT1=buymoney-r1; //申购费用临时结果
					 var resultT2=parseFloat(r1)/parseFloat(price);//申购份额临时结果
					 var paymoney =Math.round(resultT1*100)/100;//申购费用临时结果
					 var buynum=Math.round(resultT2*100)/100;//申购份额临时结果
					 document.fundsb.paymoney.value=paymoney;      //显示申购费用
           document.fundsb.rewardMoneyNum.value=buynum;        //显示申购金额
			          break;
			 //认购---和申购计算算法完全一致
		     case 2: var buymoney =document.fundsb.buyMoneyNum.value;
			         var price=document.fundsb.price.value;
					 var r1=parseFloat(buymoney)/(1+parseFloat(rate)/100);//净申购金额 
					 var resultT1=buymoney-r1; //申购费用临时结果
					 var resultT2=parseFloat(r1)/parseFloat(price);//申购份额临时结果
					 var paymoney =Math.round(resultT1*100)/100;//申购费用临时结果
					 var buynum=Math.round(resultT2*100)/100;//申购份额临时结果
					 document.fundsb.paymoney.value=paymoney;      //显示申购费用
           document.fundsb.rewardMoneyNum.value=buynum;        //显示申购金额
			          break;
			//赎回
			 case 3:var buynum =document.fundsb.buyMoneyNum.value;			        
			        var price=document.fundsb.price.value;			        
					    var r1 =parseFloat(buynum)*parseFloat(price); //赎回总额					 
					    var resultT1 =parseFloat(r1)*parseFloat(parseFloat(rate)/100); //赎回费用临时结果					  
					    var resultT2 =r1-resultT1;//赎回金额临时结果					 
					    var paymoney =Math.round(resultT1*100)/100;//赎回费用
					    var rewardmoney =Math.round(resultT2*100)/100;//赎回金额
					    document.fundsb.paymoney.value=paymoney;      //显示申购费用
              document.fundsb.rewardMoneyNum.value=rewardmoney;   //赎回金额				
			        break;
					  					  
			 }
			}
			}
	
}
 //当购买方式选择认购时，基金价格默认显示为1
 function loadRG(){
 	 if(document.fundsb.sellbuy.value=="认购")
 	 {
 	    document.fundsb.price.value =1;
 	    document.getElementById('moneyNum').innerHTML = '金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额';
 	    document.getElementById('moneyResult').innerHTML = '份&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额';
 	    document.getElementById('moneyUnit').innerHTML = '元';
 	    document.getElementById('moneyNumUnit').innerHTML = '份';
 	  }
 	  else if(document.fundsb.sellbuy.value=="申购")
 	  {
 	    document.fundsb.price.value ="";
 	    document.getElementById('moneyNum').innerHTML = '金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额';
 	    document.getElementById('moneyResult').innerHTML = '份&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额';
 	    document.getElementById('moneyUnit').innerHTML = '元';
 	    document.getElementById('moneyNumUnit').innerHTML = '份';
 	  } else if (document.fundsb.sellbuy.value=="赎回")
 	  {
 	    document.fundsb.price.value ="";
 	    document.getElementById('moneyNum').innerHTML = '份&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额';
 	    document.getElementById('moneyResult').innerHTML = '金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额';
 	    document.getElementById('moneyUnit').innerHTML = '份';
 	    document.getElementById('moneyNumUnit').innerHTML = '元';
 	  }
  
 	  document.fundsb.buyMoneyNum.value="";//购买份额或者金额
		document.fundsb.rate.value=""; //基金价格
 	  document.fundsb.paymoney.value="";      //显示申购费用
    document.fundsb.rewardMoneyNum.value="";   //赎回金额		
 	 
 	}
 	 
 	
 
</script>
</head>
<body style="background:#91c0ef url(images/bg.gif) repeat-x;">
	<img id="ccblogo" src="ccblogo.png" alt="中国建设银行－手机网" />
	<a href="shake.html">
<img id="ccblogo2" width="100px" src="http://www.baidu.com/img/bdlogo.gif" alt="百度"  />跳转本地页面
</a>

	<a href="http://www.baidu.com">
<img id="ccblogo3" width="100px" src="http://www.baidu.com/img/bdlogo.gif" alt="百度"  />跳转百度
</a>
	
<div style="width:280px;margin:0 auto;">
<div style="border:2px solid black;margin-top:20px;-webkit-border-radius:5px;padding-left:10px;padding-top:10px;-webkit-box-shadow: 10px 10px 15px #ccc;margin-bottom:20px;">

<form name="fundsb" action="counter-aa" >
  操作选择
  <select onchange="loadRG()" name="sellbuy"style="border:2px solid gray;width:110px;font-size:16px;margin-left:60px;"
>
    <option value="">请选择</option>
    <option value="认购">认购</option>
    <option value="申购">申购</option>
    <option value="赎回">赎回</option>
  </select>
  <br />
  金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额
  <input name="buyMoneyNum" size="9" maxlength="12" type="text"style="border:2px solid gray;width:105px;height:20px;font-size:16px;-webkit-border-radius:5px;margin-top:5px;margin-left:60px;">
  元 <br />
  价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格
  <input name="price" size="9" maxlength="12" type="text"style="border:2px solid gray;width:105px;height:20px;font-size:16px;-webkit-border-radius:5px;margin-top:5px;margin-left:60px;">
  元 <br />
  交易费率
  <input name="rate" size="4" maxlength="6" type="text"style="border:2px solid gray;width:105px;height:20px;font-size:16px;-webkit-border-radius:5px;margin-top:5px;margin-left:60px;">
  % <br />
  <input type="button" value="测算" onclick="fundsendprice()"style="border:2px solid gray;width:95px;height:28px;font-size:16px;-webkit-border-radius:5px;margin:10px 0px 15px 20px;"  />
  <input type="reset" value="重置" style="border:2px solid gray;width:95px;height:28px;font-size:16px;-webkit-border-radius:10px;margin:5px 0px 15px 20px;"  />
  </div>
  <div style="border:2px solid gray;margin-top:20px;-webkit-border-radius:5px;padding-left:10px;-webkit-box-shadow: 10px 10px 15px #ccc;">


  份&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额
  </td>
  <input name="rewardMoneyNum" size="9" maxlength="16" type="text"style="border:2px solid gray;width:105px;height:20px;font-size:16px;-webkit-border-radius:5px;margin-top:5px;margin-left:60px;">
  份<br />
  手&nbsp;&nbsp;续&nbsp;&nbsp;费
  <input name="paymoney" size="9" maxlength="16" type="text"style="border:2px solid gray;width:105px;height:20px;font-size:16px;-webkit-border-radius:5px;margin-top:5px;margin-left:60px;">
  元<br />
  <font color="#CC3300" style="font-size:12px;">注：此基金计算器只涵盖前端交易 </font>
</form>
</div>
</div>
</body>
</html>
